package com.oauth2_security.enums;

import java.util.HashMap;
import org.apache.commons.lang.StringUtils;

public enum SystemRest {
	
	NOT_FIND_AUTHORIZATION("9001", "无法获取请求头Authorization信息"),
    CLIENT_ID_NOT_EXISTS("9002", "clientId不存在"),
    CLIENT_ID_SECRET_ERROR("9003", "clientId密码错误"),
    CREATE_TOKEN_ERROR("9004", "创建TOKEN失败"),
    DELETE_TOKEN_ERROR("9005", "注销TOKEN失败"), 
    LOGIN_SUCCESS("200","登录成功"), 
    USER_NOT_PERMISSION("1025", "用户无权访问");
    
    private String code;
    private String msg;

    SystemRest(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static HashMap<String, String> toMap() {
        HashMap<String, String> map = new HashMap<>();
        for (SystemRest systemException : SystemRest.values()) {
            map.put(systemException.getCode(), systemException.getMsg());
        }
        return map;
    }

    public static String getMsgByCode(String code) {
        for (SystemRest systemException : SystemRest.values()) {
            if (StringUtils.equals(systemException.getCode(), code)) {
                return systemException.getMsg();
            }
        }
        return null;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
